﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TrainingsApp.WebModel;
using TrainingsApp.IPADApp.UserControls2.Student;
using TrainingsApp.WebModel.Route;
using TrainingsApp.Model;

namespace TrainingsApp.IPADApp.UserControls2.Teacher {
    public partial class UC_Index : AccountControl {

        List<IndexNotice> notics = new List<IndexNotice>(6);
        protected void Page_Load(object sender, EventArgs e) {
            Initialize();
            this.rptDataSource.DataSource = notics;
            this.rptDataSource.DataBind();
        }

        private void Initialize() {


            List<TS_Preview_Entity> previews = TrainingsApp.Logic.TS_Preview_Logic.TS_Preview_Result_TopByTeacher(this.CurPage.CurrentUser.UserID);

            if (previews != null && previews.Count > 0) {
                var entity = previews.First();
                notics.Add(new IndexNotice {
                    ModuleLink = this.CurPage.RouteHelper.Route(RouteNames.Preview_Index),
                    ModuleImage = "img/img4.gif",
                    Top1 = string.Format(@"您{0}发布了前概念问题，已有<a href=""javascript:void(0)"" >{1}</a>位同学对这个问题表达了前概念。", entity.PublishDate.ToString("yyyy-MM-dd"), previews.Sum(u => u.ReferenceTotal)),
                    Top1Link = this.CurPage.RouteHelper.Route(RouteNames.Preview_Group, new { p = entity.PreviewId }),
                    Top2 = "你还没有完成对这些前概念的整理",
                    Top2Link = this.CurPage.RouteHelper.Route(RouteNames.Preview_Group, new { p = entity.PreviewId }),
                    Style = "background-image: url(img/bg1.gif); border: 1px solid #ffbdbd;"
                });
            }
            else {
                notics.Add(new IndexNotice {
                    ModuleLink = this.CurPage.RouteHelper.Route(RouteNames.Preview_Index),
                    ModuleImage = "img/img4.gif",
                    Top1 = "暂时没有过新的前概念问题",
                    Top1Link = "javascipr:void(0)",
                    Style = "background-color:#EAEAEA; border: 1px solid #ffbdbd;",
                    Top2 = "你已经完成了对这些前概念的整理",
                    Top2Link = "javascript:void(0)"
                });
            }
        }
    }
}